<template>
	<view class="comp-order-list">
		<view class="order">

			<view class="order-box" @tap="orderDetails(item.orderSn,item.salesmanagerId)" v-for="(item,index) in list">
				<view class="title">
					<image class="decs" :src="item.pickupWay==0?'/static/images/tcps-icon.png':'/static/images/mdzt.png'" mode=""></image>
					<view class="order-num">
						订单编号：{{item.orderSn}}
					</view>

					<!-- color -->
					<!-- 超时已取消订单 -->
					<!-- 订单已取消 -->
					<!-- 仓管已取消 -->

					<view class="status" v-if="item.showStatus==-1">
						待处理
					</view>
					<view class="status" v-if="item.showStatus==1">
						待审核
					</view>
					<view class="status" v-if="item.showStatus==2">
						待接单
					</view>
					<view class="status" v-if="item.showStatus==3">
						待配送
					</view>
					<view class="status" v-if="item.showStatus==4">
						待收货
					</view>
					<view class="status" v-if="item.showStatus==5">
						已收货
					</view>
					<view class="status" v-if="item.showStatus==6">
						<text v-if="item.cancelType==1">用户已取消</text>
						<text v-if="item.cancelType==2">业务员已取消</text>
						<text v-if="item.cancelType==3">总经理已取消</text>
						<text v-if="item.cancelType==4">仓管已取消</text>
						<text v-if="item.cancelType==5">超时已取消</text>
					</view>

				</view>

				<!-- 不为司机时 -->
				<view class="shops" v-if="identity!=4">
					<image class="shops-icon" src="/static/images/shops.png" mode=""></image>
					<text class="shops-name" v-if="item.portalWarehouseInfoVo">{{item.portalWarehouseInfoVo.warehouseName}}</text>
				</view>


				<!-- 司机 -->
				<view class="addres-box" v-if="identity==4">
					<view class="jl">
						距离：{{filters.toFix(item.distance/1000)}}km
					</view>
					<view class="address">
						{{item.province}} {{item.city}} {{item.district}} {{item.address}}
					</view>
					<view class="daohang" @tap.stop="navigation(item)">
						<image src="/static/images/ditu.png" mode=""></image>
					</view>
				</view>

				<view class="order-list" v-for="(iitem,iindex) in item.goodsList">
					<image class="goods-img" :src="iitem.listPicUrl" mode=""></image>

					<view class="list-center">
						<view :class="identity==4?'order-name fontSize':'order-name'">
							{{iitem.goodsName}}
						</view>

						<view class="specification">
							{{iitem.goodsSpecifitionNameValue}}
						</view>
					</view>

					<view class="list-right">
						<view class="pic">
							￥{{iitem.retailPrice}}
						</view>

						<view class="num">
							x{{iitem.number}}
						</view>

					</view>

				</view>

				<view class="order-bottom">

					<view class="bottom-left" v-if="identity!=5">
						<view class="tag yf" v-if="item.payType==2">
							部分预付
						</view>
						<view class="tag sz" v-if="item.payType==4">
							赊账
						</view>
						<view class="tag df" v-if="item.payType==3">
							货到付款
						</view>
						<view class="tag yf" v-if="item.payType==1">
							全款
						</view>

					</view>
	
					<!-- 仓管左侧标识 -->
					<view class="bottom-left" v-if="identity==5&&item.showStatus!=2&&item.showStatus!=3">
						<view class="tag yf" v-if="item.payType==2">
							部分预付
						</view>
						<view class="tag sz" v-if="item.payType==4">
							赊账
						</view>
						<view class="tag df" v-if="item.payType==3">
							货到付款
						</view>
						<view class="tag yf" v-if="item.payType==1">
							全款
						</view>

					</view>

					<view class="bottom-left" v-if="item.pickupWay==0&&identity==5&&(item.showStatus==2||item.showStatus==3)">

						<!-- 司机名称 -->
						<view class="tag sj" >
							{{item.deliveryName}}
						</view>

					</view>
					<view class="bottom-right">
						<view class="total" >
							总金额：<text class="total-pic">￥{{item.orderPrice}}</text>
						</view>
						<!-- <view class="total" v-if="item.showStatus!=-1">
							总金额：<text class="total-pic">￥{{item.orderPrice}}</text>
						</view> -->
						<!-- <view class="total" v-if="item.couponPrice&&item.showStatus==-1">
							红包：<text class="total-pic">-￥{{item.couponPrice}}</text>
						</view>
						<view class="total"  v-if="item.activityPrice&&item.showStatus==-1">
							满减：<text class="total-pic">-￥{{item.activityPrice}}</text>
						</view> -->
						<view class="total"  v-if="item.activityPrice+item.couponPrice!=0">
							优惠金额：<text class="total-pic">-￥{{item.activityPrice+item.couponPrice}}</text>
						</view>
						<!-- ||item.showStatus==-1-->
						<view class="total"  v-if=" item.showStatus>=5||(item.showStatus==-1&&identity==2)||(item.payType!=2)">
							合计：<text class="total-pic">￥{{item.actualPrice}}</text>
						</view>
						 <!-- v-if="item.showStatus==1" -->
						<view class="yyf" v-if="(item.payType==2||item.payType==1)&&item.actualPayment">
							已预付：<text class="total-pic">￥{{item.actualPayment}}</text>
						</view>
						<view class="total" v-if="(item.payType==2||item.payType==1)&&item.actualPayment">
							剩余待支付：<text class="total-pic">￥{{filters.toFix(item.actualPrice-item.actualPayment)}}</text>
						</view>
						<!-- 总经理按钮 -->
						<template v-if="identity==3&&item.showStatus!=6&&isOrder">
							<view class="btn bg" >
								去处理
							</view>
						</template>
						<!-- 业务员按钮开始 -->
						<template v-if="identity==2&&item.showStatus!=6">

							<!-- <view class="btn bg" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="item.payType==4&&item.action==13">
								提交收款凭证
							</view> -->
							<view class="btn bg" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="item.actionResult==-1&&item.action==13">
								提交收款凭证
							</view>

							<view class="btn bg" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="item.showStatus==-1&&item.action!=13">
								去处理
							</view>
							
							<view class="shhz" v-if="(item.action==14||item.action==4)&&(item.actionResult==-1)">财务审核中...</view>

							<view class="btn" @tap.stop="qx(item.orderSn)" v-if="item.showStatus<=4">
								取消订单
							</view>
							
						</template>
						<!-- 业务员按钮结束 -->
						<!-- 仓管按钮 -->
						<template v-if="identity==5&&item.showStatus!=6">

							<view class="btn zp" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="(item.action==7||item.action==5)&&(item.payType==3||item.payType==2)&&item.pickupWay==1">
								去处理
							</view>
							<view class="btn zp" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="item.showStatus==-1&&item.action!=7&&item.pickupWay==0">
								去处理
							</view>
							<view class="btn zp" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" style="padding: 0upx 20upx;" v-if="item.pickupWay==1&&item.action==5&&item.shippingStatus<2&&(item.payType==1||item.payType==4)">
								去处理
							</view>
							<view class="btn zp" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" style="padding: 0upx 20upx;" v-if="item.pickupWay==1&&item.action==8&&item.shippingStatus<2">
								确认收货
							</view>

							<view class="btn" @tap.stop="qx(item.orderSn)" v-if="item.action==5&&item.action!=14">
								取消订单
							</view>

							<view class="shhz" v-if="item.action==14&&(item.actionResult==-1)">财务审核中...</view>


						</template>
						<!-- 仓管按钮结束 -->

						<!-- 司机按钮开始 -->
						<template v-if="identity==4&&item.showStatus!=6">

							<view class="btn jd" @tap.stop="ksps(item.orderSn,2)" v-if="item.action==12&&item.shippingStatus!=2">
								确认送达
							</view>

							<view class="btn jd" @tap.stop="ksps(item.orderSn,1)" v-if="item.action==10">
								开始配送
							</view>

							<view class="btn jd" @tap.stop="jd(item.orderSn)" v-if="item.action==9">
								接单
							</view>

							<view class="btn" @tap.stop="nojd(item.orderSn)" v-if="item.action==9">
								拒绝接单
							</view>

							<view class="btn zp" @tap.stop="orderDetails(item.orderSn,item.salesmanagerId)" v-if="item.action==11">
								提交收款凭证
							</view>
							
							<view class="shhz" v-if="item.action==14&&(item.actionResult==-1)">财务审核中...</view>
						</template>
						<!-- 司机按钮结束 -->
					</view>

				</view>

			</view>

		</view>

		<view class="dx" v-if="dx">我也是有底线的~</view>

		<view class="empty" v-if="list.length==0">
			<image src="/static/images/zwdd.png" mode=""></image>
			<view class="txt">暂无此订单</view>
		</view>
		<view class="drop" v-if="orderDrop||isNojd">
			<view class="cancel-order" v-if="orderDrop">
				<view class="tit">是否取消订单</view>
				<view class="text-box">
					<textarea class="textarea" @input="objection" value="" placeholder="请输入拒绝理由" placeholder-class="sty" />
					</view>
				
				<view class="btn-group">
					<view class="btn"  @tap="cancelOrderQx">
						取消
					</view>
					<view class="btn qr" @tap="cancelOrderQr">
						确认
					</view>
				</view>
			</view>
			
			<view class="cancel-order jdts" v-if="isNojd">
				<view class="tit">是否订拒绝接单</view>
				<view class="btn-group">
					<view class="btn"  @tap="jdQx">
						取消
					</view>
					<view class="btn qr" @tap="jdQr">
						确认
					</view>
				</view>
			</view>
			
		</view>
		
		
	</view>
</template>
<script module="filters" lang="wxs" src="../../wxs/filter.wxs"></script>
<script>
	const util = require("../../utils/util.js");
	//获取应用实例
	const api = require("../../config/api.js"); 
	export default {
		data() {
			return {
				// 拒绝理由
				reasonRefusal:'',
				// 订单遮罩控制
				orderDrop:false,
				
				// 拒绝接单
				isNojd:false,
				identity:'',
				orderId:'',
				userId:'',
				
				
			}
		},
		props:[
			"list", 
			"dx",
			"isOrder",
			"isDetail"
		],
		watch:{
			 
			  
		},
		onLoad(){
			
			this.userId = uni.getStorageSync('userInfo').userId;
			
			console.log(this.userId )
			
			// 获取身份
			// this.identity = uni.getStorageSync('identity');
			
		},
		beforeMount(){
			 this.identity = uni.getStorageSync('identity');
		},
		methods: {
			
			orderDetails(orderId,userId){
				if(this.identity==3){
					console.log(this.isDetail)
					uni.navigateTo({
						url:"/pages/orderDetails/orderDetails?orderId="+orderId+'&userId='+userId+'&isDetail='+this.isDetail
					})
				}else{
					uni.navigateTo({
						url:"/pages/orderDetails/orderDetails?orderId="+orderId+'&userId='+userId
					})
				}
				
			},
			//点击取消订单
			qx(orderSn){
				this.orderId = orderSn
				this.orderDrop = true
			},
			// 拒绝理由
			objection(e){
				this.reasonRefusal = e.detail.value;
			},
			// 取消订单确认
			cancelOrderQr(){
				console.log(this.reasonRefusal)
				// 没有填写拒绝理由
				if(!this.reasonRefusal){
					uni.showToast({
						title:'请填写拒绝理由',
						icon:'none'
					})
					
					return false
				}
				
				if(this.identity==5){
					// 仓管取消订单
					util.request(api.cgOrderSend, {
						//取消订单
						action:0,
						cancelReason:this.reasonRefusal,
						orderSn:this.orderId
					}, 'POST').then(res => {
						console.log(res)
						if(res.error==0){
							uni.showToast({
								title:'取消成功'
							})
							// this.$emit('pages')
							this.$parent.pages()
							this.$parent.getOrderList()
							
						}
						
						
					})
					
				}
				
				if(this.identity==2){
					console.log(12456)
					console.log(this.orderId)
					console.log(this.reasonRefusal)
					// 业务员取消订单
					util.request(api.orderSure, {
						//取消订单
						action:0,
						remark:this.reasonRefusal,
						orderSn:this.orderId
					}, 'POST').then(res => {
						console.log(res)
						if(res.error==0){
							uni.showToast({
								title:'取消成功'
							})
							// this.$emit('page')
							this.$parent.pages()
							this.$parent.getOrderList()
							
						}
						
						
					})
				}
				
				
				
				
				this.orderDrop = false
			},
			// 取消订单  取消
			cancelOrderQx(){
				this.orderDrop = false
			},
			
			// 司机导航
			navigation(res){
				console.log('你好')
				uni.openLocation({
					latitude: res.shippingAddress.latitude,//要去的纬度-地址       
					longitude: res.shippingAddress.longitude,//要去的经度-地址
					// latitude: 31.7335,//纬度，范围为-90~90，负数表示南纬
					// longitude: 118.1024,//经度，范围为-180~180，负数表示西经
					name: res.address,//地址名称
					address:res.province+res.city+res.district+res.address,//详细地址名称
					success: function () {
						console.log('导航成功');
					},
					fail:function(error){
						console.log(error)
					}
				});
				
			},
			// 司机开始配送
			ksps(orderSn,action){
				
				util.request(api.orderDispatch, {
					orderSn:orderSn,
					action:action
				}, 'POST').then(res => {
					console.log(res)
					uni.showToast({
						title:'成功'
					})
					// this.$emit('page',1)
					this.$parent.pages()
					this.$parent.getOrderList()
				})
			},
			// 接单
			jd(orderSn){
				util.request(api.orderTaking, {
					orderSn:orderSn,
					taking:1
				}, 'POST').then(res => {
					console.log(res)
					if(res.error==0){
						uni.showToast({
							title:'接单成功'
						})
						
						// this.$emit('page')
						this.$parent.pages()
						this.$parent.getOrderList()
					}
				})
				
			},
			// 拒绝接单
			nojd(orderSn){
				this.orderId = orderSn
			 this.isNojd = true
			},
			// 拒绝接单取消
			jdQx(){
				this.isNojd = false
			},
			// 拒绝接单确认
			jdQr(){
				util.request(api.orderTaking, {
					orderSn:this.orderId,
					taking:0
				}, 'POST').then(res => {
					console.log(res)
					if(res.error==0){
						uni.showToast({
							title:'拒绝接单成功'
						})
						// this.$emit('page')
						this.$parent.pages()
						this.$parent.getOrderList()
						this.isNojd = false
					}
				})
			}
		} 
	}
</script>

<style>
	@import url("./orderList.css"); 
</style>
